from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.core.context_processors import csrf
from django.contrib import auth

def login(request):
    response = {}
    response.update(csrf(request))        
    post = request.POST
    if post:        
        login = post['login']
        password = post['password']
        user = auth.authenticate(username=login, password=password)
        if user is not None and user.is_active:
            auth.login(request, user)            
            return HttpResponseRedirect("/")
        else:
            response.update({'error': 'true'})                
    return render_to_response("login.html", response)

def logout(request):
    auth.logout(request)
    return HttpResponseRedirect("/")
